<?php
header("Content-type:text/html;charset=utf-8");
ini_set("session.cookie_domain",'pic.dev');//注：该参数必须在sesson_start()之上，否则将不会生效,完成后可以写在php.ini中设置
ini_set('date.timezone','Asia/Shanghai');
$phpstartime = microtime();
/*2012-10-10 by yang
*@discription 配置文件
*/
 $root =  realpath(dirname(__FILE__));
 define('ROOT',$root);
 define('OUTTIME',600);
 require_once 'function/dir.php';
 foreach(getFilesPath(ROOT.'/function') as $filename)
 {
	if(basename($filename) != 'dir.php')
	{
	    require_once $filename;
	}
 }

 require_once 'class.y.php';

//smarty
require_once 'libs/smarty/Smarty.class.php';

class S extends Smarty
{	
	public function __construct()
	{		
		$this->template_suffix = 'html';	
		$this->left_delimiter = "<!--{";
		$this->right_delimiter = "}-->";
		$path = realpath($_SERVER['SCRIPT_FILENAME']);
		$this->template_dir = str_replace(ROOT,ROOT.'/templates',dirname($path));
		$this->compile_dir = str_replace(ROOT,ROOT.'/templates_c',dirname($path));	
		if(!file_exists($this->compile_dir))
		{
			_mkdir($this->compile_dir);
		}
		$this->template_name = basename($path,'.php');
	}

	public function _assign($items)
	{
		if(is_array($items))
		{
			foreach($items as $val)
			{
				global ${$val};
				$this->assign($val,${$val});
			}
		}else{
			if(!$items)
			{
				die('赋值索引为空');
			}
			global ${$items};
			$this->assign($items,$$items);
		}
	}

	public function _display($items=null)
	{
		if($items === null)
		{
			$this->display($this->template_name.'.'.$this->template_suffix);
		}else{
			$this->display($items);
		}
	}

	public function mkHtml($file_name,$items=null)
	{
		if($items === null)
		{
			$content = $this->fetch($this->template_name.'.'.$this->template_suffix);
		}else{
			$content = $this->fetch($items);
		}

		if(!$fp = fopen($file_name, "wa"))
		{    
			echo "文件打开失败！";    
			return false;    
		}
		
		if(!fwrite($fp, $content))
		{    
			echo "文件写入失败！";    
			fclose($fp);    
			return false;    
		}            
		fclose($fp);     
	}
}

$smarty = new S;

?>